<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>计算油品</title>
<link rel="stylesheet" href="${base}/static/media/css/bootstrap.css" />
<script src="${base}/static/index/vendor/jquery/jquery.min.js"></script>
<script src="${base}/static/index/vendor/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" charset="utf-8" src="${base }/static/vendor/bootstrapPager/bootstrapPager.js"></script>
<script type="text/javascript" charset="utf-8" src="${base }/static/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" charset="utf-8" src="${base }/static/js/layer/layer.js"></script>
<link href="${base }/static/css/base.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="${base }/static/css/help.css" />
<script type="text/javascript" src="${base }/static/js/jquery-1.8.1.min.js"></script>
</head>
<body onload="orderlist(1)">
	<div class="container">
		<div class="row">
			<div class="table-scrollable">
				<table class="table table-striped table-bordered table-hover" >
					<thead>
						<tr style="font-weight:bold">
							<td class="text-center">客户名称</td>
							<td class="text-center">客户电话</td>
							<td class="text-center">客户用油描述</td>
							<td class="text-center">客户用油类型</td>
							<td class="text-center">客户创建时间</td>
							<td class="text-center">分期数</td>
						</tr>
						<tr>
							<td class="text-center">${OilCustomerOrder.customerName}</td>
							<td class="text-center">${OilCustomerOrder.customerPhone }</td>
							<td class="text-center">${OilCustomerOrder.customerDescription }</td>
							<td class="text-center">
								<c:if test="${(OilCustomerOrder.customerType)==1}">
									买油送车
								</c:if>
								<c:if test="${(OilCustomerOrder.isRelease)==2 }">
									买油送油
								</c:if>
							</td>
							<td class="text-center"><fmt:formatDate value="${OilCustomerOrder.createTime}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
							<td class="text-center">${OilCustomerOrder.backByMonth }</td>
						</tr>
						<tr style="font-weight:bold">
							<td class="text-center">总金额</td>
							<td class="text-center">充值金额(原始金额)</td>
							<td class="text-center">赠送金额</td>
							<td class="text-center">释放金额</td>
							<td class="text-center">是否释放</td>
							<td class="text-center">操作</td>
						</tr>
						<tr>
							<td class="text-center">${OilCustomerOrder.totalAmount }</td>
							<td class="text-center">${OilCustomerOrder.inputOilAmount }</td>
							<td class="text-center">${OilCustomerOrder.donationAmount }</td>
							<td class="text-center">${OilCustomerOrder.releaseAmount }</td>
							<td class="text-center">
								<c:if test="${(OilCustomerOrder.isRelease)==0}">
									否
								</c:if>
								<c:if test="${(OilCustomerOrder.isRelease)==1 }">
									是
								</c:if>
							</td>
							<td class="text-center"><a class="btn btn-success btn-xs" onclick="release(${OilCustomerOrder.id},${OilCustomerOrder.isRelease })">开始释放</a></td>
						</tr>
					</thead>
				</table>
			</div>		
		</div>
		
		<div class="row">
			<div style="width: 100%;height: 15px;" >
				 <div class="btn-group btn-group-sm btn-group-solid" style="float: right;">
		            <a  href="javascript:;" onclick="addOilCustomerRelease(${OilCustomerOrder.id})" class="btn offline_serch_hide" style="margin-right:30px;background: #852B99;color:#fff;border-color:#852B99;"><i class="fa fa-search"></i>新增返现</a>
		        </div>
			</div>
			<form class="dataform" id="orderlist_form">
				<div class="table-scrollable">
					<table class="table table-striped table-bordered table-hover" >
						<thead>
							<tr>
								<th class="text-center">订单编号</th>
								<th class="text-center">100元面额充值卡</th>
								<th class="text-center">500元面额充值卡</th>
								<th class="text-center">1000元面额充值卡</th>
								<th class="text-center">释放时间</th>
								<th class="text-center">是否释放</th>
								<th class="text-center">释放金额</th>
								<th class="text-center">创建时间</th>
							</tr>
						</thead>
						<tbody id="ordercontent"></tbody>
					</table>
					<!-- 分页开始 -->    
					<ul id="page" class="pagination"></ul>
					<input type="hidden" id="pageNum" name="pageNum" value="1">
					<input type="hidden" id="pageSize" name="pageSize" value="10">
					<!-- 分页结束 -->
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		function orderlist(pageNum){
			
			$("#pageNum").val(pageNum)
			//debugger;
			var data = $("#orderlist_form").serializeArray();
			$("#ordercontent").html("")
			$.ajax({
	        	url:"${base}/buyOil/getOilCustomerRelease",
	            type:'post',
	            dataType:'json',
	            data:data,
	            success:function(res)
	            {
	                $.each(res.data.list, function(i, obj) {  
	                	var a = obj;
					    var tr = $('<tr>'); 
	                    tr.append('<td class="text-center">'+obj.customerOrderId+'</td>');
	                    if(obj.cardPart100==null){
		                    tr.append('<td class="text-center"></td>');
	                    }else{
		                    tr.append('<td class="text-center">'+obj.cardPart100+'</td>');
	                    }
	                    if(obj.cardPart500==null){
		                    tr.append('<td class="text-center"></td>');
	                    }else{
		                    tr.append('<td class="text-center">'+obj.cardPart500+'</td>');
	                    }
	                    if(obj.cardPart1000==null){
		                    tr.append('<td class="text-center"></td>');
	                    }else{
	                    	tr.append('<td class="text-center">'+obj.cardPart1000+'</td>');
	                    }
	                    tr.append('<td class="text-center">'+obj.releaseTime.substring(0,10)+'</td>');
	                    if(obj.isRelease==1){
		                    tr.append('<td class="text-center">是</td>');
	                    }else{
		                    tr.append('<td class="text-center">否</td>');
	                    }
	                    tr.append('<td class="text-center">'+obj.releaseAmount+'</td>');
	                 	tr.append('<td class="text-center">'+obj.createTime+'</td>');
	                 	
	                    //订单内容 tbody
	                    $("#ordercontent").append(tr);
					});
					var total = res.data.total; // 总条数
					var pages = res.data.pages; // 总页数
					var pageNum = res.data.pageNum; // 当前页
					var pageSize = res.data.pageSize; // 每页显示条数
					
					$("#page").html('').append(Pager({
					    totalCount:total, 		//总条数为150
					    pageSize: pageSize,    			//每页显示6条内容，默认10
					    buttonSize: 5,   		//显示6个按钮，默认10
					    pageNum: pageNum,   		//页码的参数名为'p'，默认为'page'
					    prevButton:'上一页',     //上一页按钮
					    nextButton:'下一页',     //下一页按钮
					    firstButton:'首页',      //第一页按钮
					    lastButton:'末页',       //最后一页按钮
	
					}));
	            }
	        });
	        return false;
		}
		
		// 新增分期
		function addOilCustomerRelease(id){
			layer.open({
				  type: 2,
				  title: '新增商户返现',
				  shadeClose: true,
				  shade: 0.8,
				  area: ['500px', '90%'],
				  content: '${pageContext.request.contextPath }/admin/business/cashback?id=' + id, //iframe的url
				  end:function () {
				  		location.reload();
			      }
				}); 
		}
		
		// 开始释放
		function release(id,isRelease){
			if(isRelease==1){
				layer.msg("已经开始释放,请不要重复释放", {icon: 1});
				return;
			}
			var data = {
					id:id,
					isRelease: 1
			}
			layer.confirm('是否确认开始释放?', {
				btn: ['确定','取消']
			},function(index){
				 layer.close(index);
				 $.ajax({
					 url:"${pageContext.request.contextPath}/buyOil/releaseOil",
	                 type:'post',
	                 dataType:'json',
	                 data:data,
	                 success:function(res) {
	                	 if(res.code==1){
	                		 layer.msg(res.msg, {icon: 1});
	                		 location.reload();
	                	 }else{
	                		 layer.msg(res.msg, {icon: 5});
	                	 }
	                 }
				});
				 
			});
			
			
			
		}
		
	</script>
</body>
</html>